// 设备类型
function getDeviceType() {
    const agent = navigator.userAgent.toLowerCase()

    // Android设备
    if (/android/i.test(agent)) {
        return 'android'
    }

    // iOS
    if (/iphone|ipad|ipod/i.test(agent)) {
        return 'ios'
    }

    // Window
    if (/windows/i.test(agent)) {
        return 'window'
    }

    // Mac
    var is_mac = /mac/i.test(navigator.userAgent)
    if (is_mac) {
        return 'mac'
    }

    // 默认情况下，返回未知设备类型
    return 'unknown'
}

// 是否为微信中打开
function isWeixin() {
    var agent = navigator.userAgent.toLowerCase()
    if (agent.match(/MicroMessenger/i) == "micromessenger") {
        return true
    } else {
        return false
    }
}

// 获取网络类型
function getNetworkType() {
    var agent = navigator.userAgent
    var network = agent.match(/NetType\/\w+/) ? agent.match(/NetType\/\w+/)[0] : 'NetType/other'
    network = network.toLowerCase().replace('nettype/', '')
    return network
}

export default {
    getDeviceType,
    getNetworkType,
    isWeixin
}
